package com.example.book.aspect;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
//@Component
public class TimeRecordAspect {
    @Around("com.example.book.aspect.AspectDemo.pt()")
    //目标方法:连接点
    public  Object timeRecord(ProceedingJoinPoint pjt){

        //1. 记录开始时间
        //2. 执行目标代码
        //3. 记录结束时间
        //4. 返回结果

        long start =System.currentTimeMillis();

        //执行目标代码
        Object o= null;
        try {
            o = pjt.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);

        }


        long end =System.currentTimeMillis();
        log.info(pjt.getSignature()+"XXX耗时"+(System.currentTimeMillis()-start)+"ms");
        return o;
    }
}
